package com.yb.auth.core.handler;

import com.alibaba.fastjson2.JSONObject;
import com.yb.core.bean.Resp;
import com.yb.core.constant.HttpConstant;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Copyright (C), 2022-2022, 姚兵
 * Author: 32210
 * Date: 2022/11/13 20:21
 * FileName: AuthAccessDeniedHandler
 * Description:
 */
public class AuthAccessDeniedHandler implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
            response.setContentType("application/json;charset=utf-8");
            response.getWriter().write(JSONObject.toJSONString(Resp.ok(HttpConstant.Response.NO_PERMISSION)));
    }
}
